<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>     
<%@ taglib uri="http://java.sun.com/jstl/core"			 		prefix="c"%>

<script type="text/javascript">
<!--
		
	$(document).ready(function(){
		 
		$("#exchangeForm").validate({
			rules: {
				serialNo: "required",
				vcode: "required"
			},
			messages: {
				serialNo: "请填写电子券序列号",
				vcode: "请填写电子券验证码"
			},
			 submitHandler:function() {
			 
			 	$.ajax({
					   type: "POST",
					   dataType:"json",
					   url: "${pageContext.request.contextPath}/find-exchange",
					   data: "serialNo="+$("#serialNo").val()+ "&vcode="+$("#vcode").val()+ "&t="+Math.random(),
					   success: function(data){
						   if( data.code == 0 ){
						   //再次确定是否消费
						  	
					  	 	  art.dialog({
							  	title:"确认要消费此洗车券吗？",
							    lock: true,
							    background: '#000', // 背景色
							    opacity: 0.87,	// 透明度
							    content: "洗车券（序列号"+$("#serialNo").val()+"）",
							    icon: 'succeed',
							    ok: function () {
							    
							    	$.ajax({
										   type: "POST",
										   dataType:"json",
										   url: "${pageContext.request.contextPath}/do-exchange",
										   data: "serialNo="+$("#serialNo").val()+ "&vcode="+$("#vcode").val()+ "&t="+Math.random(),
										   success: function(responseText){
												if( responseText.code == 0 ){
											  	 	  art.dialog({ icon: 'succeed', title:"成功消费",content:"已消费洗车券（序列号"+$("#serialNo").val()+"）", lock: true,ok:true});
											  	 	  $("#serialNo").val("");
											  	 	  $("#vcode").val("");
											   }else{
												   //有错误
												   art.dialog({ icon: 'error', title:"消费失败",content: responseText.msg, lock: true,ok:true});
											   }
											
										   }
										});
					
							        return true;
							    },
							    cancel: true
							});
						   }else{
						   //有错误
						   art.dialog({ icon: 'error', title:"提示",content: data.msg, lock: true,ok:true});
						   }
						
					   }
					});
			  	return false;
				
			 }
		});
		

	
	});
	
//-->
</script>
<form id="exchangeForm" >
	<div class="exchange" >
	 <ul >
	 <li>
          <c:if test="${ param.t != null }">  
          <div class="notification attention png_bg"> <a href="#" class="close"><img src="${pageContext.request.contextPath}/images/icons/cross_grey_small.png" title="关闭提示" alt="关闭" /></a>
            <div> <c:if test="${ param.t == 4 }">电子券序列号或验证码不正确</c:if> <c:if test="${ param.t == 9 }">电子券序列号或验证码不能为空</c:if></div>
          </div>
         </c:if> 
	 </li>
	 <li>
		<label style="font-size: 45px; display: inline; padding-right:10px;">电子券序列号</label>
		<input type="text" id="serialNo" name="serialNo" class="text-input medium-input" style="font-size: 50px;">
	 </li>
	 <li>
		<label style="font-size: 45px; display: inline; padding-right:10px;">电子券验证码</label>
		<input type="text"  id="vcode" name="vcode" class="text-input medium-input"  style="font-size: 50px;">
	 </li>
	 <li>
		<input type="submit" value="提 交" class="button" style="font-size: 40px;font-size: 40px !important;height:55px;line-height:50px;">
	 </li>
	 </ul>
	</div>
</form>
    <div class="clear"></div>
    <!-- End .clear -->
   